import java.util.List;

/**
 * @description:
 * @Author: wuzhenbin
 * @CreateTime: 2025-02-15
 */
public class leetcode_141 {
    public static void main(String[] args) {

    }

    public static boolean hasCycle(ListNode head) {
        ListNode headNode = new ListNode(0);
        headNode.next = head;
        ListNode slow = headNode;
        ListNode fast = head;
        while(fast!=slow&&fast!=null&&slow!=null&&fast.next!=null){
            fast = fast.next;
            slow = slow.next;
            fast = fast.next;
        }
        if(fast == slow || (fast!=null&&fast.next!=null&&fast.next==slow))return true;
        return false;
    }
    public static boolean hasCycle1(ListNode head) {
        ListNode slow = head;
        ListNode fast = head;
        while(fast!=null&&fast.next!=null){
           fast=fast.next.next;
           slow =slow.next;
            //多转几圈也没事
           if(fast == slow)return true;
        }
        return false;
    }
    static class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }
}
